home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / tjgold.zip / INSTALL.001 / GOLDHARD.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-12  |  31KB  |  1,186 lines

  1. {--------------------------------------------------------------------------}
  2. {                Product: TechnoJock's Turbo Toolkit                       }
  3. {                Version: GOLD                                             }
  4. {                Build:   1.01                                             }
  5. {                                                                          }
  6. {                Copyright 1986-1995  TechnoJock Software, Inc.            }
  7. {                           All Rights Reserved                            }
  8. {                          Restricted by License                           }
  9. {--------------------------------------------------------------------------}
  10.  
  11.                     {**********************************}
  12.                     {**       Unit:   GOLDHARD       **}
  13.                     {**********************************}
  14.  
  15. {++++++++++++++++++++++++++++++} unit GOLDHARD; {++++++++++++++++++++++++++++}
  16.  
  17. {$I GOLDFLAG.INC}
  18. {$IFNDEF GOLDHARD}
  19.    {$DEFINE GOLDHARD}
  20. {$ENDIF}
  21.  
  22. {++++++++++++++++++++++++++++++++} INTERFACE {+++++++++++++++++++++++++++++++}
  23.  
  24. uses DOS, CRT, GoldStr, GoldAttr;
  25.  
  26. const
  27.    FingerPrint: string[8] = 'EMMXXXX0';
  28.    Ignore:byte  = 255;         {background attribute}
  29.  
  30. type
  31.    ErrMsgFunc = function (Ecode:integer):string;
  32.  
  33.    gVideo = (UnKnown, Mono, CGA, MCGAMono, MCGACol, EGAMono, EGACol, VGAMono, VGACol);
  34.    OSDate = (USA,Europe,Japan);
  35.    LabelStatus = ( CorrectLabel, NoLabel, IncorrectLabel );
  36.    Str12 = string[12];
  37.  
  38.    tExFCB = record
  39.      FF: byte;           { Signals DOS that this is an ExFCB, must be $FF }
  40.      Reserved0: array[1..5] OF byte;    { Reserved By DOS, must be Zero's }
  41.      Attribute: byte;                   { Same meaning as directory entry }
  42.      DriveID: byte;                     { 0=default, 1=A, 2=B, etc }
  43.      Filename: array[1..8] OF char;  { Left justified, padded with blanks }
  44.      Extension: array[1..3] OF char; { Left justified, padded with blanks }
  45.      CurBlock: word;                 { The current block number }
  46.      RecSize: word;                  { Default of 128 bytes }
  47.      FileSize: longint;
  48.      Date: word;                     { Date created/updated }
  49.      Time: word;                     { Time created/updated }
  50.      Reserved: array[1..8] OF byte;
  51.      CurRec: byte;                   { The current record number }
  52.      Relative: longint;              { Random record number }
  53.    end;
  54.  
  55.    pMediaInfo = ^MediaInfo;
  56.    MediaInfo = record
  57.      InfoLevel: word;
  58.      SerialNumber: longint;
  59.      VolLabel: Array [ 1..11 ] of byte;
  60.      FatType: Array [ 1..8 ] of byte;
  61.    end;
  62.  
  63.    HWDataRecPtr = ^HardwareRec;
  64.    HardwareRec = record
  65.       {hardware data}
  66.       DiskInfo: SearchRec;
  67.       ThePathStr: PathStr;
  68.       MediaRec: MediaInfo;
  69.       MediaPointer: pMediaInfo;
  70.       pTheCurrentPath: pointer;
  71.       vExFCB: tExFCB;
  72.    end; { HardwareRec }
  73.  
  74.    DOSDataRecPtr = ^DOSDataRec;
  75.    DOSDataRec = record
  76.       {DOS Data}
  77.       IDPtr: pointer;
  78.       ROMPtr: pointer;
  79.       vMainInfo: word;
  80.       vComputerID: byte;
  81.       vRomDate: string[8];
  82.    end; { DOSDataRec }
  83.  
  84.    MemDataRecPtr = ^MemDataRec;
  85.    MemDataRec = record
  86.       {memory data}
  87.       Regs: registers;
  88.       ID: string[8];
  89.       vMemInfo: word;
  90.       vXMSInstalled,
  91.       vEMMInstalled: boolean;
  92.       vEMMMajor: byte;
  93.       vEMMMinor: byte;
  94.    end; { MemDataRec }
  95.  
  96.    OSDataRecPtr = ^OSDataRec;
  97.    OSDataRec = record
  98.       {OS Data}
  99.       CountryBuf: array[0..$21] of byte;
  100.       Country:word;
  101.       vMajor: byte;
  102.       vMinor: byte;
  103.       vCountry: word;
  104.       vDateFmt: OSDate;
  105.       vCurrency: string[5];
  106.       vThousands: byte;
  107.       vDecimal: byte;
  108.       vDateSeparator: byte;
  109.       vTimeSeparator: byte;
  110.       vTimeFmt: byte;
  111.       vCurrencyFmt: byte;
  112.       vCurrencyDecPlaces: byte;
  113.    end; { OSDataRec }
  114.  
  115.    HardSet = record
  116.       ECode: integer;
  117.       {screen data}
  118.       Width: byte;               {how wide is screen}
  119.       Depth: byte;               {how many lines}
  120.       ScreenPtr: pointer;        {memory location of screen data}
  121.       DisplayType: gVideo;       {video display type}
  122.       ColorSystem: boolean;      {does video support color}
  123.       ForceBW: boolean;          {use BW color schemes}
  124.       {Misc}
  125.       Regs: registers;
  126.       AnimateDelay: integer;
  127.       EMsgFunc: ErrMsgFunc;
  128.    end;
  129.  
  130. var
  131.    HardVars: HardSet;
  132.  
  133. function  LastHardError: integer;
  134. function  GetDispMode: byte;
  135. function  OSVersion(Major:boolean): byte;
  136. function  OSVersionStr: string;
  137. function  ColorScreen: boolean;
  138. function  ComputerID: byte;
  139. function  ParallelPorts: byte;
  140. function  SerialPorts: byte;
  141. function  FloppyDrives: byte;
  142. function  ROMDate: string;
  143. function  GameAdapter: boolean;
  144. function  SerialPrinter: boolean;
  145. function  MathChip: boolean;
  146. function  BaseMemory: integer;
  147. function  EMMInstalled: boolean;
  148. function  XMSInstalled: boolean;
  149. function  EMMVersionMajor: byte;
  150. function  EMMVersionMinor: byte;
  151. function  EMMVersion: string;
  152. function  OSVersionMajor: byte;
  153. function  OSVersionMinor: byte;
  154. function  Country: word;
  155. function  Currency: string;
  156. function  DateFmt: OSDate;
  157. function  ThousandsSep: char;
  158. function  DecimalSep: char;
  159. function  DateSep: char;
  160. function  TimeSep: char;
  161. function  TimeFmt: byte;
  162. function  CurrencyFmt: byte;
  163. function  CurrencyDecPlaces: byte;
  164. {hardware info}
  165. procedure ShowRegs; { for trouble shooting only }
  166. function  LastDrv: integer;
  167. function  LogicalDriveNum( Drive: char ): byte;
  168. function  PhysicalDriveNum( Drive: char ): byte;
  169. function  DriveChar( Drive: byte ): char;
  170. function  GetMediaSerialNumber( Drive: byte ): string;
  171. function  SetMediaSerialNumber( Drive: byte;Serial: longint ): boolean;
  172. function  MediaIsLabeled( Drive: byte ): boolean;
  173. function  DeleteVolumeLabel( Drive: byte ): byte;
  174. function  SetVolumeLabel( Drive: byte; LabelStr: Str12 ): byte;
  175. function  GetVolumeLabel( Drive: byte ): string;
  176. function  LabelIsCorrect( Drive: byte; LabelName: string ): LabelStatus;
  177. function  IsPhantom: boolean;
  178. function  DriveExists(Drive: char): boolean;
  179. function  DriveIsReady( Drive: byte ): boolean;
  180. procedure SetDriveTo( Drive: byte );
  181. function  CurrentDriveByte: byte;
  182. function  CurrentDriveChar: char;
  183. procedure SetCurrentDriveTo( NewDrive: char );
  184. function  CurrentPathStr: DirStr;
  185. function  SetCurrentPath( NewPath: PathStr ): boolean;
  186. function  ValidPath( Path: PathStr ): boolean;
  187.  
  188. {+++++++++++++++++++++++++++++} IMPLEMENTATION {+++++++++++++++++++++++++++++}
  189.  
  190. function LastHardError: integer;
  191. {}
  192. begin
  193.    LastHardError := HardVars.ECode;
  194. end; { LastHardError }
  195.  
  196. procedure GetOSData(var OSData:OSDataRec);
  197. {}
  198. var P: byte;
  199. begin
  200.    with HardVars do
  201.    begin
  202.       with regs do
  203.       begin
  204.          with OSData do
  205.          begin
  206.             Ah := $30;
  207.             msdos(Regs);
  208.             vMajor := Al;
  209.             vMinor := Ah;
  210.             AX := $3800;
  211.             DS := seg(CountryBuf);
  212.             DX := ofs(CountryBuf);
  213.             intr($21,Regs);
  214.             vCountry := Regs.BX;
  215.             if vMajor >= 3 then
  216.             begin
  217.                vDateFmt := OSDate(vCountry);
  218.                vCurrency := '     ';
  219.                move(CountryBuf[$2],vCurrency[1],5);
  220.                P := pos(#0,vCurrency);      {ASCIIZ string form}
  221.                if P > 0 then
  222.                   delete(vCurrency,P,5);
  223.                vThousands := CountryBuf[$7];
  224.                vDecimal := CountryBuf[$9];
  225.                vDateSeparator := CountryBuf[$B];
  226.                vTimeSeparator := CountryBuf[$D];
  227.                vTimeFmt := CountryBuf[$11];
  228.                vCurrencyFmt := CountryBuf[$F];
  229.                vCurrencyDecPlaces := CountryBuf[$10];
  230.             end else
  231.             begin
  232.                vDateFmt := OSDate(vCountry);
  233.                vCurrency := chr(CountryBuf[$2]);
  234.                vThousands := CountryBuf[$04];
  235.                vDecimal := CountryBuf[$06];
  236.                vDateSeparator := ord('/');   {not avialable before DOS 3}
  237.                vTimeSeparator := ord(':');
  238.                vTimeFmt := 1;
  239.                vCurrencyFmt := 0;
  240.                vCurrencyDecPlaces := 2;
  241.             end;
  242.          end;
  243.       end;
  244.    end;
  245. end; { GetOSData }
  246.  
  247. procedure GetDOSData(var DosData:DosDataRec);
  248. {}
  249. begin
  250.    with HardVars do
  251.    begin
  252.       with DOSData do
  253.       begin
  254.          {$IFDEF DPMI}
  255.             vComputerID := 0;
  256.             vRomdate := 'Unknown';
  257.          {$ELSE}
  258.             IDPtr := ptr($F000,$FFFE);
  259.             vComputerID := byte(IDPtr^);
  260.             ROMPtr := ptr($F000,$FFF5);
  261.             move(ROMPtr^,vROMDate[1],8);
  262.             vROMDate[0] := chr(8);
  263.             intr($11,Regs);
  264.             vMainInfo := Regs.AX;
  265.          {$ENDIF}
  266.       end;
  267.    end;
  268. end; { GetDOSData }
  269.  
  270. procedure GetMemData(var MemData:MemDataRec);
  271. {}
  272. begin
  273.    {memory}
  274.    with HardVars do
  275.    begin
  276.       with MemData do
  277.       begin
  278.          regs.AX := $4300;
  279.          intr($2F,regs);
  280.          vXMSInstalled := (regs.al = $80); {himem.sys}
  281.          {$IFDEF DPMI}
  282.             vEMMInstalled := false;
  283.          {$ELSE}
  284.             intr($12,Regs);
  285.             vMemInfo := Regs.AX;
  286.             with regs do
  287.             begin
  288.                Ah := $35;
  289.                Al := $67;
  290.                Intr($21,Regs); {ES now points to int $67 segment -- id is 10 bytes on}
  291.                move(mem[ES:$000A],ID[1],8);
  292.                ID[0] := chr(8);
  293.                vEMMInstalled := (MemData.ID = FingerPrint);
  294.             end;
  295.          {$ENDIF}
  296.             vEMMMajor := 0;
  297.             vEMMMinor := 0;
  298.             if vEMMInstalled then
  299.             begin
  300.                {get driver version number}
  301.                Regs.Ah := $46;
  302.                intr($67,Regs);
  303.                if Regs.Ah = 0 then
  304.                begin
  305.                   vEMMMajor := Regs.Al shr 4;
  306.                   vEMMMinor := Regs.AL and $F;
  307.                end;
  308.             end;
  309.       end;
  310.    end;
  311. end; { GetMemData }
  312.  
  313. procedure GetHWData(var HWData:HardWareRec);
  314. {}
  315. begin
  316.    with HardVars do
  317.    begin
  318.       with HWData.MediaRec Do
  319.       begin
  320.          InfoLevel := 0;
  321.          Fillchar(SerialNumber,SizeOf(SerialNumber),#0);
  322.          Fillchar(VolLabel,SizeOf(VolLabel),#0);
  323.          Fillchar(FatType,SizeOf(FatType),#0);
  324.       end;
  325.       HWData.MediaPointer := @HWData.MediaRec;
  326.       with HWData.vExFCB Do
  327.       begin
  328.          FF := $FF;
  329.          Fillchar(Reserved0,SizeOf(Reserved0),0);
  330.          Attribute := VolumeID;
  331.          DriveID := 1; { Default of 'A' }
  332.          Fillchar(Filename,SizeOf(Filename),' ');
  333.          Fillchar(Extension,SizeOf(Extension),' ');
  334.          CurBlock := 0;
  335.          RecSize := 0;
  336.          FileSize := 0;
  337.          Date := 0;
  338.          Time := 0;
  339.          Fillchar(Reserved,SizeOf(Reserved),0);
  340.          CurRec := 0;
  341.          Relative := 0;
  342.       end
  343.    end;
  344. end; { GetHWData }
  345.  
  346. function TestVideo: gVideo;
  347. {}
  348. var
  349.    Regs: Registers;
  350.    Equip: byte;
  351.    Temp: gVideo;
  352. begin
  353.    with Regs do
  354.    begin
  355.       Al := $00;
  356.       Ah := $1A;   {get VGA info}
  357.       Intr($10,Regs);
  358.       if Al = $1A then
  359.          case Bl of
  360.             $00: Temp := unknown;
  361.             $01: Temp := Mono;
  362.             $04: Temp := EGACol;
  363.             $05: Temp := EGAMono;
  364.             $07: Temp := VGAMono;
  365.             $08: Temp := VGACol;
  366.             $0A,
  367.             $0C: Temp := MCGACol;
  368.             $0B: Temp := MCGAMono;
  369.          else
  370.             Temp := CGA;
  371.          end {case}
  372.       else         {more checking needed}
  373.       begin
  374.          Ah := $12;
  375.          BX := $10;  {get EGA data}
  376.          Intr($10,Regs);
  377.          if BX = $10 then {EGA or Mono}
  378.          begin
  379.             Intr($11,Regs);
  380.             if ((Al and $30) shr 4) = 3 then
  381.                Temp := Mono
  382.             else
  383.                Temp := CGA;
  384.          end else
  385.          begin
  386.             Ah := $12;
  387.             BX := $10;  {one more time!}
  388.             Intr($10,Regs);
  389.             if Bh = 0 then
  390.                Temp := EGACol
  391.             else
  392.                Temp := EGAMono;
  393.          end;  {if}
  394.       end; {if}
  395.    end; {with}
  396.    TestVideo := Temp;
  397. end; { TestVideo }
  398.  
  399. function GetDispMode:byte;
  400. {}
  401. var Regs: registers;
  402. begin
  403.    with Regs do
  404.    begin
  405.       Ax := $0F00;
  406.       Intr($10,Regs);  {get video display mode}
  407.       GetDispMode := Al;
  408.    end;
  409. end; { GetDispMode }
  410.  
  411. function OSVersion(Major:boolean):byte;
  412. {if Major is false the minor version number is returned, e.g. 2 for DOS 3.2}
  413. var Regs:registers;
  414. begin
  415.    with Regs do
  416.    begin
  417.       Ah := $30;
  418.       msdos(Regs);
  419.       if Major then
  420.          OSVersion := Al
  421.       else
  422.          OSVersion := Ah;
  423.    end;
  424. end; { OSVersion }
  425.  
  426. function OSVersionStr: string;
  427. {}
  428. var OSData: OSDataRec;
  429. begin
  430.    with HardVars do
  431.    begin
  432.       GetOSData(OSData);
  433.       with OSData do
  434.          OSVersionStr := IntToStr(vMajor)+'.'+IntToStr(vMinor);
  435.    end;
  436. end; { OSVersionStr }
  437.  
  438. function ColorScreen:boolean;
  439. {}
  440. begin
  441.    with HardVars do
  442.       ColorScreen := ColorSystem and (HardVars.ForceBW = false);
  443. end; { ColorScreen }
  444.  
  445. function ComputerID: byte;
  446. {}
  447. var DosData: DosDataRec;
  448. begin
  449.    with HardVars do
  450.    begin
  451.       GetDosData(DosData);
  452.       ComputerID := DosData.vComputerID;
  453.    end;
  454. end; { ComputerID }
  455.  
  456. function ParallelPorts: byte;
  457. {}
  458. var DosData: DosDataRec;
  459. begin
  460.    with HardVars do
  461.    begin
  462.       GetDOSData(DosData);
  463.       ParallelPorts := hi(DosData.vMainInfo) shr 6;
  464.    end;
  465. end; { ParallelPorts }
  466.  
  467. function SerialPorts: byte;
  468. {}
  469. var DosData: DosDataRec;
  470. begin
  471.    with HardVars do
  472.    begin
  473.       GetDOSData(DosData);
  474.       SerialPorts := hi(DosData.vMainInfo) and $0F shr 1;
  475.    end;
  476. end; { SerialPorts }
  477.  
  478. function FloppyDrives: byte;
  479. {}
  480. var DOSData: DosDataRec;
  481. begin
  482.    with HardVars do
  483.    begin
  484.       GetDOSData(DosData);
  485.       FloppyDrives := ((DosData.vMainInfo and $C0) shr 6) + 1;
  486.    end;
  487. end; { FloppyDrives }
  488.  
  489. function ROMDate: string;
  490. {}
  491. var DosData: DosDataRec;
  492. begin
  493.    with HardVars do
  494.    begin
  495.       GetDOSData(DosData);
  496.       ROMDate := DosData.vROMDate;
  497.    end;
  498. end; { ROMDate }
  499.  
  500. function GameAdapter: boolean;
  501. {}
  502. var DosData: DosDataRec;
  503. begin
  504.    with HardVars do
  505.    begin
  506.       GetDOSData(DosData);
  507.       GameAdapter := ((DosData.vMainInfo and $1000) = 1);
  508.    end;
  509. end; { GameAdapter }
  510.  
  511. function SerialPrinter: boolean;
  512. {}
  513. var DosData: DosDataRec;
  514. begin
  515.    with HardVars do
  516.    begin
  517.       GetDOSData(DosData);
  518.       SerialPrinter := ((DosData.vMainInfo and $2000) = 1);
  519.    end;
  520. end; { SerialPrinter }
  521.  
  522. function MathChip: boolean;
  523. {}
  524. var DosData: DosDataRec;
  525. begin
  526.    with HardVars do
  527.    begin
  528.       GetDOSData(DosData);
  529.       MathChip := ((DosData.vMainInfo and $2) = $2);
  530.    end;
  531. end; { MathChip }
  532.  
  533.                         {*************************}
  534.                         {**  M E M   S T U F F  **}
  535.                         {*************************}
  536.  
  537. function BaseMemory: integer;
  538. {}
  539. var MemData: MemDataRec;
  540. begin
  541.    with HardVars do
  542.    begin
  543.       GetMemData(MemData);
  544.       BaseMemory := MemData.vMemInfo;
  545.    end;
  546. end; { BaseMemory }
  547.  
  548. function EMMInstalled: boolean;
  549. {Expanded memory}
  550. var MemData: MemDataRec;
  551. begin
  552.    with HardVars do
  553.    begin
  554.       GetMemData(MemData);
  555.       EMMInstalled := MemData.vEMMInstalled;
  556.    end;
  557. end; { EMMInstalled }
  558.  
  559. function XMSInstalled: boolean;
  560. {Extended memory}
  561. var MemData: MemDataRec;
  562. begin
  563.    with HardVars do
  564.    begin
  565.       GetMemData(MemData);
  566.       XMSInstalled := MemData.vXMSInstalled;
  567.    end;
  568. end; { XMSInstalled }
  569.  
  570. function EMMVersionMajor: byte;
  571. {}
  572. var MemData: MemDataRec;
  573. begin
  574.    with HardVars do
  575.    begin
  576.       GetMemData(MemData);
  577.       EMMVersionMajor := MemData.vEMMMajor;
  578.    end;
  579. end; { EMMVersionMajor }
  580.  
  581. function EMMVersionMinor: byte;
  582. {}
  583. var MemData: MemDataRec;
  584. begin
  585.    with HardVars do
  586.    begin
  587.       GetMemData(MemData);
  588.       EMMVersionMinor := MemData.vEMMMinor;
  589.    end;
  590. end; { EMMVersionMinor }
  591.  
  592. function EMMVersion: string;
  593. {}
  594. begin
  595.    EMMVersion := chr(EMMVersionMajor + 48)+'.'+chr(EMMVersionMinor + 48);
  596. end; { EMMVersion }
  597.  
  598.                         {*************************}
  599.                         {**  O. S.   S T U F F  **}
  600.                         {*************************}
  601.  
  602. function OSVersionMajor: byte;
  603. {}
  604. var OSData: OSDataRec;
  605. begin
  606.    with HardVars do
  607.    begin
  608.       GetOSData(OSData);
  609.       OSVersionMajor := OSData.vMajor;
  610.    end;
  611. end; { OSVersionMajor }
  612.  
  613. function OSVersionMinor: byte;
  614. {}
  615. var OSData: OSDataRec;
  616. begin
  617.    with HardVars do
  618.    begin
  619.       GetOSData(OSData);
  620.       OSVersionMinor := OSData.vMinor;
  621.    end;
  622. end; { OSVersionMinor }
  623.  
  624. function Country: word;
  625. {}
  626. var OSData: OSDataRec;
  627. begin
  628.    with HardVars do
  629.    begin
  630.       GetOSData(OSData);
  631.       Country := OSData.vCountry;
  632.    end;
  633. end; { Country }
  634.  
  635. function Currency: string;
  636. {}
  637. var OSData: OSDataRec;
  638. begin
  639.    with HardVars do
  640.    begin
  641.       GetOSData(OSData);
  642.       Currency := OSData.vCurrency;
  643.    end;
  644. end; { Currency }
  645.  
  646. function DateFmt: OSDate;
  647. {}
  648. var OSData: OSDataRec;
  649. begin
  650.    with HardVars do
  651.    begin
  652.       GetOSData(OSData);
  653.       DateFmt := OSData.vDateFmt;
  654.    end;
  655. end; { DateFmt }
  656.  
  657. function ThousandsSep: char;
  658. {}
  659. var OSData: OSDataRec;
  660. begin
  661.    with HardVars do
  662.    begin
  663.       GetOSData(OSData);
  664.       ThousandsSep := chr(OSData.vThousands);
  665.    end;
  666. end; { ThousandsSep }
  667.  
  668. function DecimalSep: char;
  669. {}
  670. var OSData: OSDataRec;
  671. begin
  672.    with HardVars do
  673.    begin
  674.       GetOSData(OSData);
  675.       DecimalSep := chr(OSData.vDecimal);
  676.    end;
  677. end; { DecimalSep }
  678.  
  679. function DateSep: char;
  680. {}
  681. var OSData: OSDataRec;
  682. begin
  683.    with HardVars do
  684.    begin
  685.       GetOSData(OSData);
  686.       DateSep := chr(OSData.vDateSeparator);
  687.    end;
  688. end; { DateSep }
  689.  
  690. function TimeSep: char;
  691. {}
  692. var OSData: OSDataRec;
  693. begin
  694.    with HardVars do
  695.    begin
  696.       GetOSData(OSData);
  697.       TimeSep := chr(OSData.vTimeSeparator);
  698.    end;
  699. end; { TimeSep }
  700.  
  701. function TimeFmt: byte;
  702. {}
  703. var OSData: OSDataRec;
  704. begin
  705.    with HardVars do
  706.    begin
  707.       GetOSData(OSData);
  708.       TimeFmt := OSData.vTimeFmt;
  709.    end;
  710. end; { TimeFmt }
  711.  
  712. function CurrencyFmt: byte;
  713. {}
  714. var OSData: OSDataRec;
  715. begin
  716.    with HardVars do
  717.    begin
  718.       GetOSData(OSData);
  719.       CurrencyFmt := OSData.vCurrencyFmt;
  720.    end;
  721. end; { CurrencyFmt }
  722.  
  723. function CurrencyDecPlaces: byte;
  724. {}
  725. var OSData: OSDataRec;
  726. begin
  727.    with HardVars do
  728.    begin
  729.       GetOSData(OSData);
  730.       CurrencyDecPlaces := OSData.vCurrencyDecPlaces;
  731.    end;
  732. end; { CurrencyDecPlaces }
  733.  
  734.                    {***********************************}
  735.                    {**  H A R D W A R E   S T U F F  **}
  736.                    {***********************************}
  737.  
  738. procedure ShowRegs;
  739. { DEVELOPERS NOTE - for trouble shooting only }
  740. var  CurX, CurY: byte;
  741. begin
  742.    with HardVars do
  743.    begin
  744.       CurX := WhereX;
  745.       CurY := WhereY;
  746.       with Regs Do
  747.       begin
  748.          GotoXY(63,1);
  749.          Write('┌──────────────┐');
  750.          GotoXY(63,2);
  751.          Write('│  Registers   │');
  752.          GotoXY(63,3);
  753.          Write('│              │');
  754.          GotoXY(63,4);
  755.          Write('│  AH - $',IntToHEXStr(AH,2):2,'    │');
  756.          GotoXY(63,5);
  757.          Write('│  AL - $',IntToHEXStr(AL,2):2,'    │');
  758.          GotoXY(63,6);
  759.          Write('│  BH - $',IntToHEXStr(BH,2):2,'    │');
  760.          GotoXY(63,7);
  761.          Write('│  BL - $',IntToHEXStr(BL,2):2,'    │');
  762.          GotoXY(63,8);
  763.          Write('│  CH - $',IntToHEXStr(CH,2):2,'    │');
  764.          GotoXY(63,9);
  765.          Write('│  CL - $',IntToHEXStr(CL,2):2,'    │');
  766.          GotoXY(63,10);
  767.          Write('│  DH - $',IntToHEXStr(DH,2):2,'    │');
  768.          GotoXY(63,11);
  769.          Write('│  DL - $',IntToHEXStr(DL,2):2,'    │');
  770.          GotoXY(63,12);
  771.          Write('│  AX - $',IntToHEXStr(AX,4):4,'  │');
  772.          GotoXY(63,13);
  773.          Write('│  BX - $',IntToHEXStr(BX,4):4,'  │');
  774.          GotoXY(63,14);
  775.          Write('│  CX - $',IntToHEXStr(CX,4):4,'  │');
  776.          GotoXY(63,15);
  777.          Write('│  DX - $',IntToHEXStr(DX,4):4,'  │');
  778.          GotoXY(63,16);
  779.          Write('│  BP - $',IntToHEXStr(BP,4):4,'  │');
  780.          GotoXY(63,17);
  781.          Write('│  SI - $',IntToHEXStr(SI,4):4,'  │');
  782.          GotoXY(63,18);
  783.          Write('│  DI - $',IntToHEXStr(DI,4):4,'  │');
  784.          GotoXY(63,19);
  785.          Write('│  DS - $',IntToHEXStr(DS,4):4,'  │');
  786.          GotoXY(63,20);
  787.          Write('│  ES - $',IntToHEXStr(ES,4):4,'  │');
  788.          GotoXY(63,21);
  789.          Write('│              │');
  790.          GotoXY(63,22);
  791.          Write('└──────────────┘');
  792.       end;
  793.       GotoXY(CurX,CurY);
  794.    end;
  795. end;  { ShowRegs }
  796.  
  797. function LastDrv: integer;
  798. {}
  799. var Regs: registers;
  800. begin
  801.    with Regs do
  802.    begin
  803.       AH := $0E;
  804.       DL := pred(CurrentDriveByte);
  805.       MsDos(Regs);
  806.       LastDrv := AL;
  807.    end;
  808. end; { LastDrv }
  809.  
  810. function LogicalDriveNum( Drive: char ): byte;
  811. {converts drive letter to logical drive byte}
  812. begin
  813.    Drive := upCase(Drive);
  814.    if ( Drive in ['A'..'Z'] ) then
  815.       LogicalDriveNum := (ord(Drive) - 65)
  816.    else
  817.       LogicalDriveNum := 0;
  818. end; { LogicalDriveNum }
  819.  
  820. function PhysicalDriveNum( Drive: char ): byte;
  821. {converts drive letter to physical drive byte}
  822. begin
  823.    Drive := upcase(Drive);
  824.    if ( Drive in ['A'..'Z'] ) then
  825.       PhysicalDriveNum := (ord(Drive) - 64)
  826.    else
  827.      PhysicalDriveNum := 0;
  828. end; { PhysicalDriveNum }
  829.  
  830. function DriveChar( Drive: byte ): char;
  831. {converts drive byte to drive char}
  832. begin
  833.   if ( Drive in [1..26] ) then
  834.      DriveChar := chr(Drive + 64)
  835.   else
  836.      DriveChar := CurrentDriveChar;
  837. end; { DriveChar }
  838.  
  839. function GetMediaSerialNumber( Drive: byte ): string;
  840. {}
  841. var Answer: string[4];
  842.     X: integer;
  843.     HWData: HardWareRec;
  844. begin
  845.    with HardVars do
  846.    begin
  847.       GetHWData(HWData);
  848.       with Regs Do
  849.       begin
  850.          AH := $69;
  851.          AL := $00;
  852.          BL := Drive;
  853.          DS := Seg(HWData.MediaPointer^);
  854.          DX := Ofs(HWData.MediaPointer^);
  855.          Intr($21,Regs);
  856.          if ( Flags AND Fcarry ) = 0 then
  857.          begin
  858.             Move(HWData.MediaPointer^.SerialNumber,Answer[1],4);
  859.             Answer[0] := #4;
  860.             GetMediaSerialNumber :=
  861.                concat(IntToHexStr(ord(Answer[4]),2),
  862.                       IntToHexStr(ord(Answer[3]),2),'-',
  863.                       IntToHexStr(ord(Answer[2]),2),
  864.                       IntToHexStr(ord(Answer[1]),2));
  865.          end else
  866.             GetMediaSerialNumber := '';
  867.       end;
  868.    end;
  869. end; { GetMediaSerialNumber }
  870.  
  871. function SetMediaSerialNumber( Drive: byte; Serial: longint ): boolean;
  872. {}
  873. var HWData: HardWareRec;
  874. begin
  875.    with HardVars do
  876.    begin
  877.       SetMediaSerialNumber := false;
  878.       GetHWData(HWData);
  879.       HWData.MediaPointer^.SerialNumber := Serial;
  880.       with Regs Do
  881.       begin
  882.          AH := $69;
  883.          AL := $01;
  884.          BL := Drive;
  885.          DS := Seg(HWData.MediaPointer^);
  886.          DX := Ofs(HWData.MediaPointer^);
  887.          Intr($21,Regs);
  888.          SetMediaSerialNumber := (( Flags AND Fcarry ) = 0)
  889.       end;
  890.    end;
  891. end; { SetMediaSerialNumber }
  892.  
  893. function MediaIsLabeled( Drive: byte ): boolean;
  894. {}
  895. var SrchRec: SearchRec;
  896. begin
  897.    MediaIsLabeled := false;
  898.    FindFirst(DriveChar(Drive) + ':\*.*',VolumeID,SrchRec);
  899.    MediaIsLabeled := (DosError = 0);
  900. end; { MediaIsLabeled }
  901.  
  902. function DeleteVolumeLabel( Drive: byte ): byte;
  903. {}
  904. var HWData: HardWareRec;
  905. begin
  906.    with HardVars do
  907.    begin
  908.       DeleteVolumeLabel := $FF;
  909.       if MediaIsLabeled(Drive) then
  910.       begin
  911.          GetHWData(HWData);
  912.          with HWData.vExFCB Do
  913.          begin
  914.             FF := $FF;
  915.             Attribute := VolumeID;
  916.             DriveID := Drive;  { A = 1, B = 2, ... }
  917.             Fillchar(Filename,8,'?');
  918.             Fillchar(Extension,3,'?');
  919.          end;
  920.          with Regs Do
  921.          begin
  922.             AH := $13;          { Delete file FCB }
  923.             DS := Seg(HWData.vExFCB);
  924.             DX := Ofs(HWData.vExFCB);
  925.             Intr($21,Regs);
  926.             DeleteVolumeLabel := AL;
  927.          end;
  928.       end;
  929.    end;
  930. end; { DeleteVolumeLabel }
  931.  
  932. function SetVolumeLabel( Drive: byte; LabelStr: Str12 ): byte;
  933. {}
  934. var I: Integer;
  935.     HWData: HardWareRec;
  936. begin
  937.    with HardVars do
  938.    begin
  939.       SetVolumeLabel := $FF;
  940.       if MediaIsLabeled(Drive) and (DeleteVolumeLabel(Drive) = 0 ) then
  941.       begin
  942.          if Pos('.',LabelStr) <> 0 then
  943.             Delete(LabelStr,Pos('.',LabelStr),1);
  944.          While Length(LabelStr) <> 11 Do
  945.          LabelStr := LabelStr + ' ';
  946.          GetHWData(HWData);
  947.          with HWData.vExFCB Do
  948.          begin
  949.             FF := $FF;
  950.             Attribute := VolumeID;
  951.             DriveID := Drive;
  952.             Fillchar(Filename,8,#0);
  953.             Fillchar(Extension,3,#0);
  954.             For I := 1 to 8 Do
  955.             Filename[I] := UpCase(LabelStr[I]);
  956.             For I := 9 to 11 Do
  957.             Extension[ I - 8 ] := UpCase(LabelStr[I]);
  958.          end;
  959.          with Regs Do
  960.          begin
  961.             AH := $16;   { Create File FCB }
  962.             DS := Seg(HWData.vExFCB);
  963.             DX := Ofs(HWData.vExFCB);
  964.             Intr($21,Regs);
  965.             with Regs Do
  966.             begin
  967.                AH := $10;         { Closes an open FCB }
  968.                DS := Seg(HWData.vExFCB);
  969.                DX := Ofs(HWData.vExFCB);
  970.                Intr($21,Regs);
  971.                SetVolumeLabel := AL;
  972.             end;
  973.          end;
  974.       end;
  975.    end;
  976. end; { SetVolumeLabel }
  977.  
  978. function GetVolumeLabel( Drive: byte ): string;
  979. {}
  980. var SrchRec: SearchRec;
  981. begin
  982.    SrchRec.Name := '';
  983.    GetVolumeLabel := '';
  984.    FindFirst(DriveChar(Drive) + ':\*.*',VolumeID,SrchRec);
  985.    if DosError = 0 then
  986.       GetVolumeLabel := Strip('A','.',SrchRec.Name)
  987. end; { GetVolumeLabel }
  988.  
  989. function LabelIsCorrect( Drive: byte; LabelName: string ): LabelStatus;
  990. {}
  991. var TempLabel: Str12;
  992. begin
  993.    if MediaIsLabeled(Drive) AND ( Length(LabelName) > 0 ) then
  994.    begin
  995.       LabelIsCorrect := IncorrectLabel;
  996.       TempLabel := GetVolumeLabel( Drive );
  997.       LabelName := Strip('A','.',LabelName);
  998.       if ( TempLabel = SetUpper( LabelName )) then
  999.          LabelIsCorrect := CorrectLabel;
  1000.    end else
  1001.       LabelIsCorrect := NoLabel;
  1002. end; { LabelIsCorrect }
  1003.  
  1004. function IsPhantom: boolean;
  1005. {}
  1006. begin
  1007.    with HardVars do
  1008.    begin
  1009.       IsPhantom := false;
  1010.       Intr($11,Regs);
  1011.       IsPhantom := (( Regs.AX AND $00C0 ) = 0 );
  1012.       { Could probably read: IsPhantom := (FloppyDrives = 1); }
  1013.    end;
  1014. end;
  1015.  
  1016. function DriveExists(Drive: Char): boolean;
  1017. {}
  1018. var
  1019.   Regs:registers;
  1020.   StartDrive: byte;
  1021. begin
  1022.    drive := upcase(Drive);
  1023.    if not (ord(drive) in  [65..90]) then
  1024.       DriveExists := false
  1025.    else
  1026.    with Regs do
  1027.    begin
  1028.       StartDrive := CurrentDriveByte;
  1029.       Ah := $0E;           {select the drive to be tested}
  1030.       Dl := ord(drive) - 65;
  1031.       intr($21,Regs);
  1032.       Ah := $19;           {get the current drive again}
  1033.       intr($21,Regs);
  1034.       DriveExists :=  Al = ord(drive) - 65;
  1035.       if PhysicalDriveNum(drive) = 2 then
  1036.          DriveExists := not IsPhantom;
  1037.       SetCurrentDriveTo(DriveChar(StartDrive));
  1038.    end;
  1039. end; { DriveExists }
  1040.  
  1041. function DriveIsReady( Drive: byte ): boolean;
  1042. {}
  1043. begin
  1044.    with HardVars do
  1045.    begin
  1046.       DriveIsReady := false;
  1047.       if ( FloppyDrives = 1 ) then
  1048.          SetDriveTo(Drive);
  1049.       with Regs Do
  1050.       begin
  1051.          AH := $32;    { Get DOS drive parameter block }
  1052.          DL := Drive;    { $00=default, $01=A, $02=B ... }
  1053.          Intr($21,Regs);
  1054.          DriveIsReady := (AL = 0);
  1055.       end;
  1056.    end;
  1057. end; { DriveIsReady }
  1058.  
  1059. procedure SetDriveTo( Drive: byte );
  1060. { Eliminates "Insert diskette in drive" message }
  1061. begin
  1062.    with HardVars do
  1063.    begin
  1064.       if FloppyDrives = 1 then
  1065.       case Drive of
  1066.          1: Mem[$0000:$0504] := 00;
  1067.          2: Mem[$0000:$0504] := 01;
  1068.       end;
  1069.    end;
  1070. end; { SetDriveTo }
  1071.  
  1072. function CurrentDriveByte: byte;
  1073. {}
  1074. var Regs: registers;
  1075. begin
  1076.    with Regs do
  1077.    begin
  1078.       AH := $19;    { Get Default Drive }
  1079.       Intr($21,Regs);
  1080.       CurrentDriveByte := AL + 1;
  1081.    end;
  1082. end; { CurrentDriveByte }
  1083.  
  1084. function CurrentDriveChar: char;
  1085. {returns the character of the current drive}
  1086. begin
  1087.    CurrentDriveChar := chr(CurrentDriveByte + 64);
  1088. end; { CurrentDriveChar }
  1089.  
  1090. procedure SetCurrentDriveTo( NewDrive: char );
  1091. {}
  1092. begin
  1093.    with HardVars do
  1094.    begin
  1095.       if ( Ord(Upcase(NewDrive)) - 64 ) <= FloppyDrives then
  1096.       Fillchar(Regs,SizeOf(Regs),#0);
  1097.       with Regs Do
  1098.       begin
  1099.          AH := $0E;    { Select Disk }
  1100.          DL := Ord(NewDrive) - 65;
  1101.          Intr($21,Regs);
  1102.       end;
  1103.    end;
  1104. end; { SetCurrentDriveTo }
  1105.  
  1106. function CurrentPathStr: DirStr;
  1107. {returns the current path string.
  1108.  this excludes the final backslash}
  1109. var TempStr: dirstr;
  1110. begin
  1111.    GetDir(0,TempStr);
  1112.    CurrentPathStr := TempStr;
  1113. end; { CurrentPathStr }
  1114.  
  1115. function SetCurrentPath( NewPath: PathStr ): boolean;
  1116. {}
  1117. begin
  1118.    if NewPath[length(NewPath)] = '\' then
  1119.       delete(NewPath,length(NewPath),1);
  1120.    {$I-} ChDir(NewPath); {$I+}
  1121.    SetCurrentPath  := (IOResult = 0);
  1122. end; { SetCurrentPath }
  1123.  
  1124. function ValidPath( Path: PathStr ): boolean;
  1125. {}
  1126. var PathLen,
  1127.     gResult: Integer;
  1128.     FN: file;
  1129. begin
  1130.    PathLen := Length( Path );
  1131.    if ( Path[PathLen] = '\' ) AND
  1132.       ( Path[Pred(PathLen)] <> ':' ) then
  1133.       Delete(Path,PathLen,1);
  1134.    assign(FN,Path+'\nul');
  1135.    {$I-} reset(FN); {$I+}
  1136.    ValidPath := (IOResult = 0)
  1137. end; { ValidPath }
  1138.  
  1139.               {**********************************************}
  1140.               {**  U N I T    I N I T I A L I Z A T I O N  **}
  1141.               {**********************************************}
  1142.               
  1143. procedure HardDefaultSettings;
  1144. {}
  1145. begin
  1146.    with HardVars do
  1147.    begin
  1148.       ForceBW := false;
  1149.       AnimateDelay := 100;
  1150.    end;
  1151. end; { HardDefaultSettings }
  1152.  
  1153. procedure GoldHardInit;
  1154. {internal}
  1155. var DM:integer;
  1156. begin
  1157.    HardDefaultSettings;
  1158.    with HardVars do
  1159.    begin
  1160.       ECode := 0;
  1161.       DisplayType := TestVideo;
  1162.       DM := GetDispMode;
  1163.    {$IFDEF DPMI}
  1164.       if DM = 7 then
  1165.          ScreenPtr := ptr(segB000,0) {Mono}
  1166.       else
  1167.          ScreenPtr := ptr(segB800,0); {Color}
  1168.    {$ELSE}
  1169.       if DM = 7 then
  1170.          ScreenPtr := ptr($B000,0) {Mono}
  1171.       else
  1172.          ScreenPtr := ptr($B800,0); {Color}
  1173.    {$ENDIF}
  1174.    {$IFDEF FORCEMONO}  {for debugging colors on dual monitors}
  1175.          ScreenPtr := ptr(segB000,0); {Color}
  1176.    {$ENDIF}
  1177.       ColorSystem := DM <> 7;
  1178.       Width := 80;
  1179.       Depth := succ(Hi(WindMax));
  1180.    end;
  1181. end; { GoldHardInit }
  1182.  
  1183. begin
  1184.    GoldHardInit;
  1185. end.
  1186.